<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>电影资料维护</title>
    <jsp:include page="/IncludeJS.jsp"></jsp:include>
</head>
<body onload="init();">
<script type="text/javascript">
    let videoType = ["mp4"];

    function save() {
        document.forms[0].submit();
    }

    function check() {
        if ($("#file").val() === ""){
            alert("请选择上传的视频");
            $('#file').focus();
            return false;
        }else {
            let type = $("#file").val().match(/^(.*)(\.)(.{1,8})$/)[3].toLowerCase();
            for(var i in videoType){
                if (videoType[i] !== type){
                    alert("您选择的不是视频文件!")
                    return false
                }
            }
        }
        if ($("#movieid").val() === "-1"){
            alert("请选择视频所属的电影")
            $('#movieid').focus();
            return false;
        }
        if ($("#title").val() === "") {
            alert("请标题名称");
            $('#title').focus();
            return false;
        }
        if ($("#description").val() == "") {
            alert("请输入视频简介");
            $('#description').focus();
            return false;
        }
        return true;
    }

    function back() {
        location.href = "${pageContext.request.contextPath }/video/list";
    }

    if ("${msg}" != null && "${msg}".length > 0) {
        alert("${msg}");
    }

    function init() {
        var key = $("#id").val();
        if (key == "0") {
            var d = new Date();
            var y = d.getFullYear();
            var m = d.getMonth() + 1;
            var d = d.getDate();
            $("#registerTime").datebox("setValue", y + "-" + m + "-" + d);
        } else {
            var td = $("#registerTime").val();
            if (td != "" && td.substring(0, 1) != '2') {
                td = "20" + td;
                $("#registerTime").datebox("setValue", td.substring(0, 10));
            }
        }
    }
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" BACKGROUND="images/maintitle.jpg">
    <tr>
        <td align="left">
            <a class="easyui-linkbutton" plain="true" icon="icon-undo" href="javascript:void(0);"
               onclick="back();">返回</a>
        </td>
    </tr>
</table>
<form action="${pageContext.request.contextPath }/video/save" enctype="multipart/form-data" method="post"
      onsubmit="return check();">
    <table cellpadding="0" cellspacing="0" border="0" style="margin: 0 auto" align="left">
        <tr height="30">
            <td align="right">视频</td>
            <td><input type="file" name="file" id="file"></td>

        </tr>
        <tr height="30">
            <td align="right" width="120">所属电影</td>
            <td><select id="movieid" name="movieid">
                <option value="-1">请选择</option>
                <c:forEach items="${movies}" var="m">
                    <option value="${m.movieId}" <c:if test="${video.movieid==m.movieId}">selected</c:if> >${m.movieName}</option>
                </c:forEach>
            </select>
                <font size="2" color="red">*</font>
            </td>
        </tr>
        <tr height="30">
            <td align="right" width="120">标题</td>
            <td><input type="text" name="title" id="title" style="width:250px" value="${video.title}"/>
                <font size="2" color="red">*</font>
            </td>
        </tr>
        <tr height="30">
            <td align="right" width="90" style="vertical-align: top">简介</td>

            <td colspan="3">
                <textarea name="description" id="description" style="width:630px;height:350px">${video.description}</textarea>
            </td>

        </tr>

        <tr height="30">
            <td>&nbsp;</td>
            <td colspan="3"><input type="submit" value="   保 存   "/></td>
        </tr>
    </table>
</form>
</body>
</html>